package com.han.hotelplat.dao.childtask;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.han.hotelplat.comm.base.BaseDAO;
import com.han.hotelplat.pojo.childtask.Childtask;

@Repository
public class ChildTaskDao extends BaseDAO<Childtask>{

	public List<Childtask> getTaskAttendance(String taskid, String date) {
		String hql = "select new Childtask(ct.id, ct.taskid, ct.creattime, ct.emid, "
				+ "ct.roomcount, ct.reward, ct.auditor, ct.result, ct.remark, em.realname) "
				+ "from Childtask as ct , Employee as em where ct.emid = em.userid "
				+ " and ct.taskid='"+taskid+"'"
				+ " and ct.creattime='"+date+"'";
		return findByHQL(hql);
	}

	public List<Childtask> getEmTaskAttendance(String taskid, String userid, String date) {
		String hql = "from Childtask where taskid='"+taskid+"'"
				+" and emid='"+userid+"'";
		if(StringUtils.isNotBlank(date)){
			hql += " and creattime >= '"+date+"'";
		}
		hql += " order by creattime desc ";
		return findByHQL(hql);
	}

	public Childtask getTaskAttendance(String taskid, String date, String emid) {
		String hql = "select new Childtask(ct.id, ct.taskid, ct.creattime, ct.emid, "
				+ "ct.roomcount, ct.reward, ct.auditor, ct.result, ct.remark, em.realname) "
				+ "from Childtask as ct , Employee as em where ct.emid = em.userid "
				+ " and ct.taskid='"+taskid+"'"
				+ " and ct.creattime='"+date+"'"
				+ " and ct.emid='"+emid+"'";
		 List<Childtask> li = findByHQL(hql);
		return li.size() == 0?null:li.get(0);
	}

	public List<Childtask> getAllEmTaskAttendance(String taskid, Integer state) {
		String hql = "select new Childtask(ct.id, ct.taskid, ct.creattime, ct.emid, "
				+ "ct.roomcount, ct.reward, ct.auditor, ct.result, ct.remark, em.realname) "
				+ "from Childtask as ct , Employee as em where ct.emid = em.userid "
				+ " and ct.taskid='"+taskid+"'";
		if(state != null){
			hql = hql + " and ct.result ="+state ;
		}
		hql += " order by ct.creattime desc ";
		return findByHQL(hql);
	}
}
